import 'package:flutter/cupertino.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:mtf/app/net/HttpManger.dart';
import 'package:mtf/app/utils/cache/AppCahche.dart';
/**
 * GetX Template Generator - fb.com/htngu.99
 * */

class editEmailController extends GetxController{
  TextEditingController emailController = TextEditingController();
  var user = AppCache.getUserInfo().obs;

  @override
  void onInit() {
    super.onInit();
    emailController.text=user.value.mailbox??"";
  }

  void clickMailbox() async{
    var mailbox = emailController.text;

    if (mailbox.isEmpty) {
      SmartDialog.showToast("请输入您的电子邮箱");
    }else{
      var resp=await HttpManager.reqUpdateInfo(mailbox: mailbox);
      reqUserInfo();
    }
  }

  void reqUserInfo() async {
    var resp=await HttpManager.reqUserInfo();
    if(resp.isSuccess()&&resp.data!=null){
      AppCache.setUserInfo(resp.data!);
      user.value = resp.data!;
      SmartDialog.showNotify(msg: "修改成功", notifyType: NotifyType.success);
      Get.back();
    }
  }
}
